package com.gewu.pm.bean;

import java.io.Serializable;

/**
 * 商品数据模型
 */
public class GoodsBean implements Serializable {

    private static final long serialVersionUID = 1L;
    
    /** 商品ID */
    private String id;
    /** 商品名称 */
    private String name;
    /** 商品图片URL */
    private String imageUrl;
    /** 标签（如：促销） */
    private String tag;
    /** 卖点 */
    private String sellingPoint;
    /** 库存（0-10随机值） */
    private int stock;
    /** 保质期 */
    private String shelfLife;
    /** 商品编码 */
    private String code;
    /** 价格 */
    private String price;
    /** 当前选择数量（默认0） */
    private int quantity;
    /** 商品单位（箱、包、盒、瓶、袋等） */
    private String unit;

    public GoodsBean() {
        this.quantity = 0;
    }

    public GoodsBean(String id, String name, String tag, String sellingPoint, 
                     int stock, String shelfLife, String code, String price) {
        this.id = id;
        this.name = name;
        this.tag = tag;
        this.sellingPoint = sellingPoint;
        this.stock = stock;
        this.shelfLife = shelfLife;
        this.code = code;
        this.price = price;
        this.quantity = 0;
    }

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getImageUrl() {
        return imageUrl;
    }

    public void setImageUrl(String imageUrl) {
        this.imageUrl = imageUrl;
    }

    public String getTag() {
        return tag;
    }

    public void setTag(String tag) {
        this.tag = tag;
    }

    public String getSellingPoint() {
        return sellingPoint;
    }

    public void setSellingPoint(String sellingPoint) {
        this.sellingPoint = sellingPoint;
    }

    public int getStock() {
        return stock;
    }

    public void setStock(int stock) {
        this.stock = stock;
    }

    public String getShelfLife() {
        return shelfLife;
    }

    public void setShelfLife(String shelfLife) {
        this.shelfLife = shelfLife;
    }

    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }

    public String getPrice() {
        return price;
    }

    public void setPrice(String price) {
        this.price = price;
    }

    public int getQuantity() {
        return quantity;
    }

    public void setQuantity(int quantity) {
        this.quantity = quantity;
    }
    
    /**
     * 增加数量
     * @return true-增加成功，false-库存不足
     */
    public boolean increaseQuantity() {
        if (quantity < stock) {
            quantity++;
            return true;
        }
        return false;
    }
    
    /**
     * 减少数量
     * @return true-减少成功，false-已经为0
     */
    public boolean decreaseQuantity() {
        if (quantity > 0) {
            quantity--;
            return true;
        }
        return false;
    }
    
    /**
     * 是否有库存
     */
    public boolean hasStock() {
        return stock > 0;
    }

    public String getUnit() {
        return unit;
    }

    public void setUnit(String unit) {
        this.unit = unit;
    }
}

